package com.kamistoat.meimeistore.order.vo;


import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要的信息
 */
public class OrderCheckVo {
    // 防止重复提交的唯一令牌
    String orderToken;
    // 用户的所有收货地址
    List<MemberAddressVo> memberAddressVoList;
    // 购物车中所有选中的购物项
    List<OrderItemVo> orderItemVoList;
    // 库存情况
    Map<String, Boolean> hasStockMap;
    // 用户积分
    Integer integration;
    // 积分满减
    BigDecimal integrationPrice;
    // 商品总类数
    String orderCount;
    // 订单原价
    BigDecimal totalPrice;
    // 叠加优惠后的应付价格
    BigDecimal realPrice;

    /**
     * 是否为秒杀订单
     */
    Boolean isSeckill = false;
    /**
     * 秒杀订单的Long sessionProId
     */
    Long sessionProId;
    /**
     * 秒杀订单的String randomCode
     */
    String randomCode;
    /**
     * 秒杀商品skuId
     */
    private Long skuId;
    /**
     * 购买限额
     */
    private Integer wantNum;


    public Map<String, Boolean> getHasStockMap() {
        return hasStockMap;
    }

    public void setHasStockMap(Map<String, Boolean> hasStockMap) {
        this.hasStockMap = hasStockMap;
    }

    public String getOrderToken() {
        return orderToken;
    }

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }

    public Boolean getIsSeckill() {
        return this.isSeckill;
    }

    public void setIsSeckill(Boolean isSeckill) {
        this.isSeckill = isSeckill;
    }

    public Long getSessionProId() {
        return sessionProId;
    }

    public void setSessionProId(Long sessionProId) {
        this.sessionProId = sessionProId;
    }

    public String getRandomCode() {
        return randomCode;
    }

    public void setRandomCode(String randomCode) {
        this.randomCode = randomCode;
    }

    public Long getSkuId() {
        return skuId;
    }

    public void setSkuId(Long skuId) {
        this.skuId = skuId;
    }

    public Integer getWantNum() {
        return wantNum;
    }

    public void setWantNum(Integer wantNum) {
        this.wantNum = wantNum;
    }

    public List<MemberAddressVo> getMemberAddressVoList() {
        return memberAddressVoList;
    }

    public void setMemberAddressVoList(List<MemberAddressVo> memberAddressVoList) {
        this.memberAddressVoList = memberAddressVoList;
    }

    public List<OrderItemVo> getOrderItemVoList() {
        return orderItemVoList;
    }

    public void setOrderItemVoList(List<OrderItemVo> orderItemVoList) {
        this.orderItemVoList = orderItemVoList;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    // 种类数可以直接自己算
    public String getOrderCount() {
        Integer totalCount = 0;
        Integer nullCount = 0;
        if (this.orderItemVoList != null && this.orderItemVoList.size() > 0) {
            for (OrderItemVo orderItemVo : this.orderItemVoList) {
                totalCount = totalCount + 1;
                if (!this.hasStockMap.get(orderItemVo.getSkuId().toString())) {
                    nullCount = nullCount + 1;
                }
            }
        }
        return "共" + totalCount.toString() + "种商品，其中" + nullCount.toString() + "件无货";
    }

    public BigDecimal getIntegrationPrice() {
        BigDecimal integrationPrice = new BigDecimal("0");
        integrationPrice = (BigDecimal.valueOf(this.integration)).divide(new BigDecimal("100"));
        return integrationPrice;
    }

    // 总价可以直接自己算
    public BigDecimal getTotalPrice() {
        BigDecimal totalPrice = new BigDecimal("0");
        if (this.orderItemVoList != null && this.orderItemVoList.size() > 0) {
            for (OrderItemVo orderItemVo : this.orderItemVoList) {
                // 只有有货商品才算入总价中
                if (this.getHasStockMap().get(orderItemVo.getSkuId().toString())) {
                    totalPrice = totalPrice.add(orderItemVo.getTotalPrice());
                }
            }
        }
        return totalPrice;
    }

    // 实际价格也直接自己算
    public BigDecimal getRealPrice() {
        BigDecimal realPrice = new BigDecimal("0");
        BigDecimal totalPrice = getTotalPrice();
        realPrice = totalPrice.subtract(this.getIntegrationPrice());
        return realPrice;
    }

}
